<template>
	<view class="login-box">
		<uni-icons type="contact-filled" size="160"></uni-icons>
		<button type="primary" open-type="getUserInfo" @getuserinfo="getUserInfo">登录</button>
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex'
	export default {
		name:"my-login",
		data() {
			return {
				
			}
		},
		computed:{
			...mapState('user',['userInfo'])
		},
		methods:{
			...mapMutations('user',['updateUserInfo','updateToken']),
			getUserInfo(e){
				if(e.detail.errMsg=='getUserInfo:ok'){
					this.updateUserInfo(e.detail.userInfo)
					//this.getToken(e.detail)
				}else{
					uni.$showMsg('权限不足，登录失败')
				}
			},
			/* async getToken(detail){

				const res = await uni.login()

				const query = {
					code:res.code,
					encrypteData:detail.encryptedData,
					iv:detail.iv,
					rawData:detail.rawData,
					signature:detail.signature
				}
				//测试接口损坏，在参数正确的情况下仍然提示‘缺少必要的参数’，错误码400，暂时使用随机数代替token，后续修复接口后进行对应调整
				//const {data:loginResult} = await uni.$http.post('/api/public/v1/users/wxlogin',query)
				this.updateToken(Math.random())
			} */
		}
	}
</script>

<style lang="scss">
	.login-box{
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 100px;
		width: 100%;
		button{
			background-color: green;
			width: 500rpx;
			border-radius: 20px;
			overflow: hidden;
			&:hover{
				background-color: seagreen;
			}
		}
		
	}
</style>